home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v9n03.arc / LODBOOT.ASM < prev    next >
Assembly Source File  |  1990-01-12  |  36KB  |  623 lines

  1.          PAGE  60,132
  2.          TITLE LODboot - Boot and partition sector reload program.
  3. ;        SUBTTL  General program description and use of common storage
  4. ; ----------------------------------------------------------------------------;
  5. ;        LODboot - ReLoad Boot or partition sectors from CHKboot created files;
  6. ;-----------------------------------------------------------------------------;
  7. ;   LODBOOT 1.0 ■ PCDATA TOOLKIT Copyright (c) 1990 Ziff Communications Co.   ;
  8. ;                       PC Magazine ■ Wolfgang Stiller                        ;
  9. ;                                                                             ;
  10. ;-----------------------------------------------------------------------------;
  11. ;Purpose:                                                                     ;
  12. ;  To recover from damage to either the DOS boot sector or a hard disk's      ;
  13. ;  partition sector (table). LODBOOT will read the boot or partition          ;
  14. ;  sector reload file created by CHKboot, verify that it has not been         ;
  15. ;  corrupted and then reload the appropriate sector.                          ;
  16. ;-----------------------------------------------------------------------------;
  17. ;Format:                                                                      ;
  18. ;                                                                             ;
  19. ;    LODBOOT [/B] [/P] [/2]                                                   ;
  20. ;                                                                             ;
  21. ;  Only one of the above parameters can be specified at a time.               ;
  22. ;                                                                             ;
  23. ; /B  Reloads the boot record from the file @@BOOT.SCT which was previously   ;
  24. ;     created by an execution of "CHKboot /I".                                ;
  25. ; /P  Reloads the partition sector onto the first physical hard disk drive    ;
  26. ;     from file @@PARTIT.SCT.                                                 ;
  27. ; /2  Same as "/P" but writes to second physical fixed disk drive.            ;
  28. ;-----------------------------------------------------------------------------;
  29. ;Remarks:                                                                     ;
  30. ; LODBOOT will not reload both a boot and a partition sector at the same      ;
  31. ; time.  If both are damaged, the partition sector should be reloaded         ;
  32. ; first. LODBOOT will check the .SCT reload files and will refuse to          ;
  33. ; reload if the files have been corrupted. Both reload files contain 32       ;
  34. ; bits of integrity check information.                                        ;
  35. ;                                                                             ;
  36. ; In order to reload a DOS boot sector, the file @@BOOT.SCT must be in        ;
  37. ; the current directory which must be on the DOS disk(ette) to be             ;
  38. ; reloaded.  To reload a partition sector, the file @@PARTIT.SCT must be      ;
  39. ; in the current directory. This need not be on the disk to be reloaded.      ;
  40. ;                                                                             ;
  41. ; LODBOOT will return the following DOS errorlevels:                          ;
  42. ; 00 - Reload of boot or partition sector was successful.                     ;
  43. ; 32 - Invalid or missing reload file (@@BOOT.SCT or @@PARTIT.SCT).           ;
  44. ; 64 - I/O error occurred while trying disk read/write.                       ;
  45. ;128 - No parameters entered or invalid syntax.                               ;
  46. ;                                                                             ;
  47. ;-----------------------------------------------------------------------------;
  48.  
  49. ;---------------------------------------------------------------;
  50. ; Constants:                                                    ;
  51. ;---------------------------------------------------------------;
  52. BOX          EQU    254                   ;Small box character code
  53. CR           EQU    0Dh
  54. LF           EQU    0Ah
  55. CRLF         EQU    0A0Dh                 ;Carriage return line feed.
  56. Boot_type    EQU    0FFh                  ;Indicator of a boot sector (.PRM)
  57. Part_type    EQU    055h                  ;Indicator of a partition sector(.PRM)
  58. ; Double line drawing character definitions
  59. Horizontal   EQU    205                   ;Horizontal double line
  60. Vertical     EQU    186                   ;Vertical double line
  61. UPRT_corner  EQU    187                   ;Upper righthand corner
  62. UPLT_corner  EQU    201                   ;Upper lefthand corner
  63. LWLT_corner  EQU    200                   ;Lower lefthand corner
  64. LWRT_corner  EQU    188                   ;Lower righthand corner
  65.  
  66. CSEG    SEGMENT
  67.         ASSUME  CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
  68.  
  69.         SUBTTL  Main program
  70. ;******************************************************************************;
  71. ;**   Main program begins here -LODBOOT-                                     **;
  72. ;******************************************************************************;
  73.         ORG     100H                      ; THIS IS A COM TYPE PROGRAM
  74. LODBOOT:
  75.         CALL    Parse_parms               ;Parse cmdline paramters + prnt header
  76.  
  77.         MOV     DX, offset Header_Msg     ;Put out title display
  78.         MOV     AH,09H                    ;DOS display string function
  79.         INT     21H
  80.  
  81. ; Check system sector size
  82.         MOV     AH,36h                    ;Check sector size and free space
  83.         XOR     DL,DL                     ;Check current disk (DL=0 is current)
  84.         INT     21h
  85.         MOV     Sector_Size,CX            ;Save # of bytes per sector
  86.  
  87.         XOR     BP,BP                     ;Zero out highest error level code
  88.         CMP     Boot_wanted,'Y'           ;Does user want BOOT rec loaded?
  89.         JNE     No_Boot                   ;  If not skip loading the boot rec
  90.         CALL    Read_Boot_SCT             ;Read and verify the relaod file
  91.         CALL    Write_Boot_Sector         ;Do actual write of sector 0 (DOS)
  92. NO_BOOT:
  93.         CMP     Partition_wanted,'Y'      ;Does user want Partition loaded?
  94.         JNE     End_Execution             ;  If not skip loading the Partition
  95.         CALL    Read_Part_SCT             ;Read and verify the relaod file
  96.         CALL    Write_Part_Sector         ;Do actual BIOS write of partition
  97. End_Execution:                            ;Successful termination of program
  98.         MOV     AX,BP                     ;BP contains highest error level
  99.         MOV     AH,4Ch                    ;DOS terminate with errorlevel funct
  100.         INT     21h
  101.  
  102.  
  103.  
  104.  
  105. ;---------------------------------------------------;
  106. ; C O M P A R E      B U F F E R      S U M S       ;
  107. ;---------------------------------------------------;
  108. ;Register conventions:                              ;
  109. ;                                                   ;
  110. ; DI - Contains checksum for this file              ;
  111. ; DX - XOR sum                                      ;
  112. ;---------------------------------------------------;
  113. Compare_Buffer_Sums:                      ;See if any changes to the sector
  114.         CMP     WORD PTR[SCT_CW1],'oW'    ;Any change to check word?
  115.         JNE     Buffer_change_detected    ;  If not =, report the change
  116.         CMP     WORD PTR[SCT_CW2],'gn'    ;Any change to check word?
  117.         JNE     Buffer_change_detected    ;  If not =, report the change
  118.         CMP     WORD PTR[SCT_Ind],0FFFFh  ;Any change to indicator word?
  119.         JNE     Buffer_change_detected    ;  If not =, report the change
  120.         CMP     SCT_XOR,DX                ;Any change to XOR sum?
  121.         JNE     Buffer_change_detected    ;  If not =, report the change
  122.         CMP     SCT_CHK,DI                ;Is the checksum OK?
  123.         JNE     Buffer_change_detected    ;  If not, report the change
  124.                                           ;  ELSE all is OK with Buffer sector
  125.         MOV     DX,offset OK_Msg          ;Explain that all is well
  126.         MOV     AH,09H                    ;DOS display string function
  127.         INT     21h
  128.         RET
  129.  
  130. Buffer_Change_detected:                   ;Report problem with Buffer record
  131.         MOV     DX,offset Bad_Msg         ;Explain that its bad
  132.         MOV     AH,09H                    ;DOS display string function
  133.         INT     21H
  134. Missing_or_Invalid_Reload_File:
  135.         CALL    Wait_For_Key              ;Beep and force user to hit a key
  136.         MOV     AX,4C20h                  ;DOS terminate with 32 error level
  137.         INT     21h
  138.  
  139. ;---------------------------------------------------;
  140. ; W R I T E    B O O T   S E C T O R                ;
  141. ;---------------------------------------------------;
  142. ;Write the DOS boot sector using DOS I/O requests.  ;
  143. ;---------------------------------------------------;
  144. Write_Boot_Sector:
  145.         PUSH    BP                        ;Save all current registers
  146. Try_boot_write_again:                     ;Come here to retry the extended
  147.        ;form of the write if normal int 26h failed. Note, it is NOT an error
  148.        ;that we re-execute the 19h function...some systems require this
  149.         MOV     DX,offset Boot_Msg        ;Display message about boot record
  150.         MOV     AH,09H                    ;DOS display string function
  151.         INT     21H
  152.         MOV     AH,19h                    ;DOS get current disk drive function
  153.         INT     21h                       ;Get current disk drive in AL (0=A)
  154.         CMP     DOS_Version,4             ;Are we running under DOS 4.x?
  155.         JNE     Old_DOS                   ;If not, do normal int 26 call
  156. ; Process DOS 4.0 disks using extended format of INT26 (handles disks > 32mb)
  157.         MOV     CX,-1                     ;Set indicator to handle >32 mb disks
  158.         MOV     BX,Offset INT26_Parms     ;Point to 10 byte parameter block
  159.         MOV     Buffer_Segment,DS         ;Segment address in parameter block
  160.         JMP     SHORT DOS_Abs_Write       ;Do DOS Absolute sector read
  161. Old_DOS:
  162.         MOV     CX,1                      ;Write just one sector
  163.         XOR     DX,DX                     ;DX=0 to write DOS relative sector 0
  164.         MOV     BX,Offset buffer          ;Place to put the sector
  165. DOS_Abs_Write:
  166.         INT     26h                       ;DOS absolute disk write function
  167.         JNC     Boot_write_OK             ;If I/O was successful
  168.                                           ;Else we had an I/O error
  169. ;
  170. ; Since some OEM versions of DOS such as COMPAQ 3.31 also support the extended
  171. ; format of the int 26h call for disks > 32mb we will lie and say this is
  172. ; DOS 4.x and try the interrupt 4.0 using the extended format call.
  173.         POPF                              ;Restore flags INT 26 put on stack
  174.         CMP     DOS_Version,4             ;Did we already try DOS 4.x type int?
  175.         JE      Unrecoverable_IO_Error    ;  If so, then boot Write failed
  176.                                           ;  otherwise try extended int 26h
  177.         MOV     DOS_Version,4             ;  Force extended int 26h use (lie)
  178.         JMP     SHORT Try_Boot_Write_Again ;  do func 19h and then extd int 26h
  179.  
  180. Unrecoverable_IO_Error:                   ;Exit here if I/O has failed
  181.         MOV     DX,offset IO_ERR_MSG      ;Explain that input/output failed
  182.         MOV     AH,09H                    ;DOS display string function
  183.         INT     21H
  184. Error_termination:
  185.         CALL    Wait_For_Key              ;Beep and force user to hit a key
  186.         MOV     AX,4C40h                  ;   terminate with 64 DOS ERRORLEVEL
  187.         INT     21h
  188. Boot_write_OK:
  189.         POPF                              ;restore flags pushed by INT 26h
  190.         POP     BP                        ;Restore active registers
  191.         MOV     DX,offset BOOT_Done       ;Tell user that all is OKeeDOKEY
  192.         MOV     AH,09H                    ;DOS display string function
  193.         INT     21H
  194.         RET
  195.  
  196.  
  197. Open_Failure:                             ;Come here when open of .SCT fails
  198.         MOV     DX,offset Open_Fail_Msg   ;Explain that open failed
  199.         MOV     AH,09H                    ;DOS display string function
  200.         INT     21H
  201.         JMP     SHORT Missing_or_Invalid_Reload_File  ;Alert to serious problem
  202.  
  203.  
  204. ;---------------------------------------------------;
  205. ; W R I T E    P A R T   S E C T O R                ;
  206. ;---------------------------------------------------;
  207. ;Write the partition sector using BIOS I/O request  ;
  208. ;---------------------------------------------------;
  209. Write_part_Sector:
  210.         MOV     DX,offset Part_Msg        ;Display writing partition sectr msg
  211.         MOV     AH,09H                    ;DOS display string function
  212.         INT     21H
  213.         MOV     AH,03                     ;BIOS floppy write function of INT 13h
  214.         MOV     DL,BYTE PTR[Drive_number] ;Drive 80 (1st) or 81 (2nd) hard drive
  215.         MOV     AL,1                      ;Write only 1 sector
  216.         MOV     CX,1                      ;Write (CH) track 0, (CL) sector 1
  217.         XOR     DH,DH                     ;write head number zero
  218.         MOV     BX,Offset buffer          ;Place to put the sector
  219.         INT     13h                       ;BIOS absolute (floppy) disk write
  220.         JNC     Part_write_OK             ;If I/O was successful
  221.                                           ;Else the we had an I/O error
  222.         MOV     DX,offset No_HardDisk_MSG ;Display message about missing part
  223.         MOV     AH,09H                    ;DOS display string function
  224.         INT     21H
  225.         JMP     SHORT Unrecoverable_IO_Error
  226. Part_write_OK:
  227.         MOV     DX,offset Part_Done       ;Tell user that all is OKeeDOKEY
  228.         MOV     AH,09H                    ;DOS display string function
  229.         INT     21H
  230.         RET
  231.  
  232. ;---------------------------------------------------;
  233. ; R E A D    B O O T   S E C T O R   (F I L E)      ;
  234. ;---------------------------------------------------;
  235. ;Read the reloadable version of the boot sector from;
  236. ;DISK. Also validate the boot sector after reading. ;
  237. ;---------------------------------------------------;
  238. Read_Boot_SCT:
  239.         MOV     DX,offset BootR_MSG       ;Display msg about reading .SCT file
  240.         MOV     AH,09H                    ;DOS display string function
  241.         INT     21H
  242.         MOV     AX,3D00h                  ;DOS open file for read command
  243.         MOV     DX,Offset Boot_File_Name
  244.         INT     21h
  245.         JNC     Open_Boot_OK              ;IF all went OK then return
  246.         JMP     Open_Failure              ;Inform user that open failed
  247. Open_Boot_OK:
  248.         MOV     BX,AX                     ;Handle for Boot sector file
  249.         MOV     AH,3Fh                    ;DOS Read function code
  250.         MOV     CX,581                    ;read 581 bytes from disk
  251.         MOV     DX,OFFSET Read_Buffer     ;Location to put data from disk
  252.         INT     21h                       ;Do the I/O
  253.         JNC     Boot_Read_OK              ;If I/O was successful
  254.                                           ;Else the we had an I/O error
  255.         JMP     Buffer_Change_Detected    ;Tell user that reload file is bad
  256. Boot_Read_OK:                             ;Read of reload file was OK
  257.         MOV     AH,3Eh                    ;DOS close file function code
  258.         INT     21h                       ;Close the file
  259.         CALL    Calc_Sums                 ;Calculate CHK and XOR sums
  260.         CALL    Compare_Buffer_Sums       ;Verify that they match
  261.         CMP     BYTE PTR[SCT_Type],Boot_type  ;Is it really a boot sector?
  262.         JE      Boot_Validate_Done        ;  yes it is...
  263.         JMP     Buffer_Change_Detected    ;  else, Report the error to the user
  264. Boot_Validate_Done:
  265.         RET
  266.  
  267.  
  268. ;---------------------------------------------------;
  269. ; R E A D    P A R T   S E C T O R   (F I L E)      ;
  270. ;---------------------------------------------------;
  271. ;Read reloadable version of the partition sector.   ;
  272. ;Also validate the itegrity of the reload file.     ;
  273. ;---------------------------------------------------;
  274. Read_Part_SCT:
  275.         MOV     DX,offset PartR_MSG       ;Display msg about writing Part file
  276.         MOV     AH,09H                    ;DOS display string function
  277.         INT     21H
  278.         MOV     AX,3D00h                  ;DOS open file for read command
  279.         MOV     DX,Offset Part_File_Name
  280.         INT     21h
  281.         JNC     open_Part_OK              ;IF all went OK then return
  282.         JMP     OPEN_Failure              ;Inform user that open failed
  283. Open_Part_OK:
  284.         MOV     BX,AX                     ;Handle for Part sector file
  285.         MOV     AH,3Fh                    ;DOS Read function code
  286.         MOV     CX,581                    ;Read 581 bytes from disk
  287.         MOV     DX,OFFSET Read_Buffer     ;Location to put data from disk
  288.         INT     21h                       ;Do the I/O
  289.         JNC     Part_Read_OK              ;If I/O was successful
  290.                                           ;Else the we had an I/O error
  291.         JMP     Buffer_Change_Detected    ;Tell user that reload file is bad
  292. Part_Read_OK:                             ;Read of partition reload file OK
  293.         MOV     AH,3Eh                    ;DOS close file function code
  294.         INT     21h                       ;Close the file
  295.         CALL    Calc_Sums                 ;Calculate CHK and XOR sums
  296.         CALL    Compare_Buffer_Sums       ;Verify that they match
  297.         CMP     BYTE PTR[SCT_Type],Part_type  ;Is it really a boot sector?
  298.         JE      Part_Validate_Done        ;  yes it is...
  299.         JMP     Buffer_Change_Detected    ;  else, Report the error to the user
  300. Part_Validate_Done:
  301.         RET
  302.  
  303.  
  304.         SUBTTL  General Purpose subroutines
  305.         PAGE
  306. ;******************************************************************************;
  307. ;**   General purpose subroutines follow                                     **;
  308. ;******************************************************************************;
  309.         SUBTTL  General purpose subroutines
  310.         PAGE
  311. ;---------------------------------------------------;
  312. ; C A L C     S U M S  - Calculate XOR + CHK sums   ;
  313. ;---------------------------------------------------;
  314. ; INPUT:  reads 1st sector in BUFFER to scan        ;
  315. ;                                                   ;
  316. ;Register conventions:                              ;
  317. ;                                                   ;
  318. ; AL - Each new character read into this register   ;
  319. ; CX - number of chars read in -decreasing counter  ;
  320. ; DI - Contains checksum for this file              ;
  321. ; DX - XOR sum                                      ;
  322. ; SI - index pointing into file BUFFER              ;
  323. ; --------------------------------------------------;
  324. Calc_Sums:
  325.         MOV     SI,offset BUFFER          ;Point SI to buffer containing sector
  326.         MOV     CX,Sector_Size            ;Process all bytes in a sector
  327.         XOR     DX,DX                     ;Zero XOR sum
  328.         XOR     DI,DI                     ;Zero CHK sum
  329.         XOR     AH,AH                     ;Zero upper part of AX for addition
  330.  
  331. ; Innermost read char loop  - keep this fast!
  332. NEXT_CHAR:
  333.         LODSB                             ;Get char into AL
  334.         XOR     DL,AL                     ;cumulative XOR into DX
  335.                                           ;following instr modified by /X parm
  336. ROL_op: ROL     DX,1                      ;Keep shifting to XOR sum to left
  337.                                           ;following instr modified by /C parm
  338. ADD_op: ADD     DI,AX                     ;cumulative check sum
  339.         LOOP    NEXT_CHAR                 ;CONTINUE SCANNING CHARS UNTIL EOB
  340.         RET                               ;All done calculating sums!
  341.  
  342. ;---------------------------------------------------;
  343. ; W A I T   F O R   K E Y                           ;
  344. ;---------------------------------------------------;
  345. ; 1) Send out a BEEP                                ;
  346. ; 2) Determine screen attribute (screen colors)     ;
  347. ; 3) Determine what line cursor is on               ;
  348. ; 4) Put out message to hit any key on that line    ;
  349. ; 5) Wait for any key press                         ;
  350. ; 6) Erase message using current screen attribute   ;
  351. ; 7) Position currsor back at start of current line.;
  352. ; --------------------------------------------------;
  353. ; *** NO REGISTERS ARE SAVED ***                    ;
  354. ; --------------------------------------------------;
  355. Wait_For_Key:                             ;Force user to notice error
  356. ; Produce a beep to alert the user:  (use  BIOS TTY func to write an ASCII BELL)
  357.         MOV     AX,0E07H                  ;BIOS func (0Eh) to write (07H) beep
  358.         XOR     BH,BH                     ;Select page zero for output
  359.         INT     10H                       ;BIOS video function (0Eh=write char)
  360.  
  361. ;Find out what attribute is being used for display
  362.         MOV     AH,08h                    ;read attrib + char function
  363.         INT     10h                       ;Call BIOS
  364.         PUSH    AX                        ;Save AH=attribute byte
  365.  
  366. ;Find out what line the cursor is on
  367.         MOV     AH,03h                    ;Read cursor position function
  368.         INT     10h                       ;BIOS video services
  369.         PUSH    DX                        ;DH contains row (line #) Save it!
  370.  
  371. ; Position cursor to current line + column 28: (TO BIOS  row 27)
  372.         MOV     AH,02                     ;BIOS int 10h set cursor position func
  373.         XOR     BH,BH                     ;Set page to zero
  374.                                           ;DH contains current row
  375.         MOV     DL,1Bh                    ;Set cusor current row and col 27
  376.         INT     10h                       ;BIOS video services
  377.  
  378. ; Put -Hit any key- message out with inverse video attribute type on
  379. ;       XOR     BH,BH                     ;Set page to zero  (BH is still 0)
  380.         MOV     BL,0F0h                   ;Inverse video attribute
  381.         MOV     CX,1                      ;Character count
  382.         MOV     SI,offset Hit_Key_Msg     ;The hit-any-key message
  383. Display_next_video_char:
  384.         MOV     AH,09H                    ;BIOS int 10h write attrib + char func
  385.         LODSB                             ;Get next character for output
  386.         PUSH    SI                        ;Save SI (int 10h may corrupt it)
  387.         INT     10h                       ;Put character and attribute out
  388.         INC     DX                        ;Advance cursor position
  389.         MOV     AH,02                     ;Adv cursor function
  390.         INT     10h                       ;   advance the cursor (BIOS)
  391.         POP     SI                        ;Restore saved SI
  392.         CMP     SI,offset Hit_key_Msg_end ;are we at end of message?
  393.         JB      Display_next_video_char   ;  If not get next char for display
  394.                                           ;  Else, wait for key press by user
  395. ; Wait for user to hit any key
  396.         XOR     AX,AX
  397.         INT     16h                       ;Wait for user to hit a key
  398.  
  399. ; Erase HIT ANY KEY message
  400.         POP     DX                        ;DH=current line number
  401.         POP     BX                        ;BH=user's screen attribute
  402.         MOV     AH,06h                    ;INIT window function
  403.         XOR     AL,AL                     ;Zero AL to clear window
  404.         MOV     CH,DH                     ;Current row (y coor upr lft)
  405.         MOV     CL,00                     ;Start in first char position
  406.         MOV     DL,79                     ;Last char pos - blank entire line
  407.         INT     10h                       ;Blank out line
  408.  
  409. ; Position cursor to start of blanked line
  410.         MOV     AH,02                     ;BIOS int 10h set cursor position func
  411.         XOR     DL,DL                     ;DH=cur line, DL=0: first char pos
  412.         XOR     BX,BX                     ;Use video page zero
  413.         INT     10h                       ;BIOS video services
  414.         RET                               ;Return to caller
  415.  
  416.  
  417.         SUBTTL  Initialization Code
  418.         PAGE
  419. ; ----------------------------------------------------------------------------;
  420. ; Initialization code - parse parms + put out msgs                            ;
  421. ; ----------------------------------------------------------------------------;
  422. Parse_parms:                              ;Parse input parameters
  423.         MOV     AH,30h                    ;Check DOS version
  424.         INT     21h                       ;    Ask DOS: "who are you?"
  425.         OR      AL,AL                     ;Check if before DOS 2.x (AL=0)
  426.         JNE     DOS_is_OK                 ;If good DOS vers, then continue
  427.         MOV     DX, OFFSET Bad_DOS_Msg    ;   ELSE  Send MSG that
  428.         MOV     AH,09h                    ;   DOS version is too low.
  429.         INT     21h
  430.         INT     20h                       ;  Old style DOS terminate interupt
  431. DOS_is_OK:
  432.         MOV     DOS_Version,AL            ;Save major DOS version number (0-4)
  433.         MOV     SI,80H                    ;Parameter area in PSP
  434.         MOV     CL,[SI]                   ;Get # of chars in input parm
  435.         XOR     CH,CH                     ;CLEAR UPPER BYTE OF CHR COUNT
  436.         OR      CL,CL                     ;CHECK FOR 0 CHARS (NO INPUT)
  437.         MOV     DX, OFFSET Explanation    ;Give user full explanation of prgm
  438.         JNZ     Continue_parse            ;If some parameters keep going
  439.         JMP     Help_display              ; Else, give user some help info
  440. Continue_parse:
  441.         INC     SI                        ;POINT TO FIRST CHARACTER
  442.         CLD                               ;FORWARD DIRECTION
  443.  
  444. DEL_SPACES:
  445.         LODSB                             ;Get byte at DS:SI and inc SI
  446.         CMP     AL,'/'                    ;Is it a "/"
  447.         JE      Scan_for_parms            ;If so, we have a parameter
  448.         LOOP    DEL_SPACES                ;CONT CHECKING UNTIL LAST CHAR
  449.         JMP     Help_Display
  450.  
  451. ;---------------------------------------------------------------------------;
  452. ; Conventions for command line parsing:                                     ;
  453. ;   SI points to next char to be checked in the parm field at DS:80         ;
  454. ;   CX is count of characters left to be scanned                            ;
  455. ;---------------------------------------------------------------------------;
  456.  
  457. Scan_for_parms:
  458.         CMP     CX,01                     ;Check if we out of chars to scan
  459.         JA      Parm_Scan                 ;If some are left, check parameters
  460.         JMP     Help_display              ;If so, user needs HELP
  461.  
  462. Check_parm_chars_left:                    ;Check if enough chars left for a parm
  463.         CMP     CX,01                     ;Check if we out of chars to scan
  464.         JA      Parm_Scan                 ;  if not continue chcking for /parms
  465.         RET                               ;  If so, return
  466. Parm_Scan:                                ;Check for presence of a /_ parm
  467.         CMP     AL,'/'                    ;check for "/" parm character
  468.         JE      Parm_found
  469.         CMP     AL,' '                    ;check for blanks
  470.         JNE     Unrecog_parm              ;If other than blank its illegal...
  471.         LODSB                             ;Keep checking next character
  472.         LOOP    Parm_Scan
  473.         RET                               ;All done
  474.  
  475. Parm_Found:                               ;Check if parm is valid
  476.         DEC     CX                        ;Adjust chars remaining counter
  477.         JCXZ    Unrecog_parm              ;IF no chars left then parm is invalid
  478.         LODSB                             ;Get next char
  479.         DEC     CX                        ;Adjust chars remaining counter
  480.         CMP     AL,'2'                    ;Is it the Initialize parm?
  481.         JE      Two_parm                  ;2 parm detected..
  482.         AND     AL,5Fh                    ;Capitalize char
  483.         CMP     AL,'P'                    ;Is it Partition table parm?
  484.         JE      P_parm                    ;P parameter detected
  485.         CMP     AL,'B'                    ;Is it the Boot record parm?
  486.         JE      B_parm                    ;I parm detected..
  487. Unrecog_parm:                             ; an illegal paramter:
  488.         MOV     DX, offset Bad_Parm_Msg   ;indicate illegal parm was found
  489.         MOV     AH,09H                    ;DOS display string function
  490.         INT     21H
  491.         JMP     SHORT ERR_Exit            ;terminate with error level set
  492.  
  493. Too_Many_Parms:                           ;User has entered more than 1 parm
  494.         MOV     DX, offset Too_ManyP_Msg  ;indicate more than 1 found
  495.         MOV     AH,09H                    ;DOS display string function
  496.         INT     21H
  497.         JMP     SHORT ERR_Exit            ;terminate with error level set
  498.  
  499. P_parm:
  500.         CMP     Parm_Already_Found,'Y'    ;Is this the 2nd parm?
  501.         JE      Too_Many_Parms            ;  If so, give error message
  502.         MOV     Partition_wanted,'Y'      ;Indicate user wants partition table
  503.         MOV     Parm_Already_Found,'Y'    ;Indicate user has entered a parm
  504.         LODSB                             ;Keep checking next character
  505.         JMP     SHORT Check_Parm_chars_left     ;Check for additional parms
  506.  
  507. B_parm:
  508.         CMP     Parm_Already_Found,'Y'    ;Has user already selected /P
  509.         JE      Too_Many_Parms            ;  If so, give error message
  510.         MOV     Boot_wanted,'Y'           ;Indicate user wants boot record
  511.         MOV     Parm_Already_Found,'Y'    ;Indicate user has entered a parm
  512.         LODSB                             ;Keep checking next character
  513.         JMP     SHORT Check_Parm_chars_left     ;Check for additional parms
  514.  
  515. Two_parm:                                 ;/2 parm (read partition on 2nd disk)
  516.         CMP     Parm_Already_Found,'Y'    ;Has user already selected /P
  517.         JE      Too_Many_Parms            ;  If so, give error message
  518.         MOV     Partition_wanted,'Y'      ;Indicate user wants a partition table
  519.         MOV     Partition2_wanted,'Y'     ;Indicate user wants 2nd partitn table
  520.         MOV     Parm_Already_Found,'Y'    ;Indicate user has entered a parm
  521.         INC     Drive_number              ;Write drive num 81 (2nd hard drive)
  522.         LODSB                             ;Keep checking next character
  523.         JMP     Check_Parm_chars_left     ;Check for additional parms
  524.  
  525. ERR_EXIT:
  526.         CALL    Wait_For_Key              ;Beep and force user to hit a key
  527. Syntax_msg_only:
  528.         MOV     DX, offset Syntax_Msg     ;show user correct syntax
  529. Help_Display:
  530.         MOV     AH,09H                    ;DOS display string function
  531.         INT     21H
  532.         MOV     AX,4C80h                  ;   terminate with 128 DOS ERRORLEVEL
  533.         INT     21h
  534.  
  535.  
  536.  
  537.         SUBTTL  Definition of Data structures
  538.         PAGE
  539. ;******************************************************************************;
  540. ;**   Definition of Data areas follow                                        **;
  541. ;******************************************************************************;
  542. Boot_wanted         DB 'N'                ;Read DOS boot sector Y or N?
  543. Partition_Wanted    DB 'N'                ;Read any Partition sector Y or N?
  544. Partition2_Wanted   DB 'N'                ;Read part on 2nd disk Y or N?
  545. Parm_Already_found  DB 'N'                ;Read part on 2nd disk Y or N?
  546. DOS_Version         DB 00                 ;Major version of DOS used (0 - 4)
  547. Sector_Size         DW 00                 ;Number of bytes per sector
  548.  
  549. INT26_Parms         LABEL BYTE            ;DOS 4.0 INT25/26 parameter block
  550. Sector_Number       DD  00                ;DOS logical sector number to write
  551. Sector_Count        DW  01                ;Write 1 sector
  552. Buffer_Offset       DW  OFFSET Buffer     ;Buffer address - offset
  553. Buffer_Segment      DW  0                 ;  segment - set at run time
  554.  
  555. BootR_MSG     DB  'Reading "@@BOOT.SCT."',CR,LF,'$'
  556. PartR_MSG     DB  'Reading "@@PARTIT.SCT".',CR,LF,'$'
  557. IO_ERR_Msg    DB  'An unrecoverable I/O error has occurred.',CR,LF,'$'
  558. No_hardDisk_MSG DB  'Partition sector not processed. Unable to write to disk'
  559.               DB  CR,LF,'$'
  560. Open_Fail_Msg DB  'Unable to open the (.SCT) reload file.',CR,LF,'$'
  561. Part_Msg      DB  'Writing the partition sector....','$'
  562. Boot_Msg      DB  'Writing the DOS boot sector....','$'
  563. Part_done     DB  'Partition sector successfully reloaded.',CR,LF,'$'
  564. Boot_done     DB  'Boot sector successfully reloaded.',CR,LF,'$'
  565. Bad_DOS_Msg   DB  'DOS 2.x or higher required.',CR,LF,'$'
  566. OK_Msg        DB  'Sector reload file (.SCT) is '
  567.               DB  ' valid.',CR,LF,'$'
  568. Bad_Msg       DB  ' Sector reload file (*.SCT) is corrupted (changed).',CR,LF
  569.               DB  'It is not safe to reload from it.',CR,LF,'$'
  570. Hit_Key_MSG   DB   '-Hit any key-'
  571. Hit_Key_MSG_end EQU $
  572. Boot_File_name DB '@@BOOT.SCT',00         ;ASCIIZ string of boot sector file
  573. Part_File_name DB '@@PARTIT.SCT',00       ;ASCIIZ string of partition file
  574. Drive_number  DW  80h                     ;Drive number for BIOS hard disk read
  575. Too_ManyP_Msg DB  'Only one parameter may be used at a time (/B, /P or /2).'
  576.               DB   cr,lf,lf,'$'
  577. Bad_Parm_Msg  DB  'Unrecognized parameter detected.',cr,lf,'$'
  578. Explanation DB  'LODBOOT will reload either the DOS boot record or the '
  579.             DB   'partition sector',CR,LF
  580.             DB  '(not both at the same time) from the "@@BOOT.SCT" or the'
  581.             DB  ' "@@PARTIT.SCT"',CR,LF
  582.             DB  'reload files. These files are created by "CHKboot/I".  These'
  583.             DB  ' files must be on',CR,LF
  584.             DB  'the disk and directory from which you run LODBOOT.'
  585.             DB  CR,LF,LF
  586. Syntax_Msg  DB  CR,LF,'Syntax is: LODBOOT  [/B] [/P] [/2]',CR,LF,LF
  587.             DB  ' "/B"  Reads "@@BOOT.SCT" and reloads the DOS boot record on '
  588.             DB  'the current disk.',CR,LF
  589.             DB  ' "/P"  Reads "@@PARTIT.SCT" and reloads partition sector on '
  590.             DB  '1st physical hard',CR,LF
  591.             DB  '       disk drive.',CR,LF
  592.             DB  ' "/2"  Reloads partition sector on 2nd physical hard disk.'
  593.             DB  CR,LF,LF
  594.             DB  'Only one of the above parameters may be specified at a time.'
  595.             DB  CR,LF,LF
  596.             DB  'The ".SCT" reload files must be created by program "CHKboot". '
  597.             DB  'LODBOOT',CR,LF
  598.             DB  'will detect if the ".SCT" files have changed.  If these files '
  599.             DB  'have been',CR,LF
  600.             DB  'corrupted (changed), LODBOOT will refuse to reload the sectors'
  601.             DB  '.',CR,LF,LF
  602.  
  603. Header_msg    LABEL  BYTE
  604.   DB UPLT_Corner,76 DUP(Horizontal),UPRT_Corner,CR,LF
  605.   DB vertical,"  LODBOOT 1.0 ■ PCDATA TOOLKIT Copyright (c) 1990 Ziff "
  606.   DB "Communications Co.   ",vertical,CR,LF
  607.   DB Vertical,"                     PC Magazine ■ Wolfgang Stiller    "
  608.   DB "                     ",vertical,CR,LF
  609.   DB LWLT_Corner,76 DUP(Horizontal),LWRT_Corner,CR,LF,'$'
  610.  
  611. Read_Buffer DB  'LODBOOT reload file. Copy me to a floppy.abc'
  612. SCT_CW1     DB  'defghi'             ;Check word 1 in header
  613. SCT_CW2     DB  'jklmnopqrs',CR,LF      ;word 2
  614. SCT_Ind     DW  0FFFFh                  ;Special boot/partition indicator
  615. SCT_TYPE    DB  0FFh                    ;Indicate if this is boot or part rec
  616.                                         ; FF=Boot and 55=Partition sector
  617. SCT_CHK     DW  00h                     ;CHK SUM
  618. SCT_XOR     DW  00h                     ;XOR SUM
  619. Buffer      label  byte                 ;All storage + code following is in
  620.                                         ;   the input file buffer.
  621. CSEG        EndS
  622.             END     LODBOOT
  623.